import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:tin_flutter/ui/widget/common_product_horizontal_widget.dart';
import 'package:tin_flutter/ui/widget/common_title_widget.dart';

import '../../../../../app/res/app_color.dart';
import '../../../../../app/res/intl.dart';
import '../../../../../app/tools/logger.dart';
import '../../main_logic.dart';

/// * 作者: Tao
/// * 日期: 2025/11/4
/// * 时间: 16:42
/// * 描述: 人气推荐模块
class HotProductWidget extends StatefulWidget {

  const HotProductWidget({Key? key}) : super(key: key);

  @override
  State<HotProductWidget> createState() => _HotProductWidgetState();
}

class _HotProductWidgetState extends State<HotProductWidget> {
  final state = Get.find<MainLogic>().state;

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: EdgeInsets.only(top: 8.0, bottom: 8.0),
      child: Container(
        decoration: BoxDecoration(
          color: AppColor.white,
          borderRadius: BorderRadius.all(Radius.circular(5.0)),
        ),
        child: Padding(
          padding: EdgeInsets.all(12.0),
          child: Column(
            children: [
              // 标题栏
              CommonTitleWidget(
                  imageUrl: 'assets/images/icon_hot_product.png',
                  title: Intl().hotProductTitle,
                  content: Intl().hotProductContent,
                  onTap: () {
                    logger('点击了${Intl().hotProductTitle}');
                  }),
              SizedBox(height: 5.0),
              // 列表
              ListView.builder(
                  scrollDirection: Axis.vertical,
                  shrinkWrap: true,
                  physics: NeverScrollableScrollPhysics(),
                  padding: EdgeInsets.all(5.0),
                  itemCount: state.hotProductList.length,
                  itemBuilder: (context, index) {
                    return CommonProductHorizontalWidget(
                        imageUrl: state.hotProductList[index].pic,
                        title: state.hotProductList[index].name,
                        content: state.hotProductList[index].subTitle,
                        price: state.hotProductList[index].price.toInt());
                  })
            ],
          ),
        ),
      ),
    );
  }
}
